{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a2e47132",
   "metadata": {},
   "source": [
    "---\n",
    "*日期：2022-10-19/week09     \n",
    "*课程：python        \n",
    "*记录人：lm      "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55c6ebb0",
   "metadata": {},
   "source": [
    " # 本周学习目标\n",
    " 1.列表的方法   \n",
    " \n",
    " 2.while循环\n",
    " \n",
    " \n",
    " ## 1.列表的方法\n",
    "1.使用.Tab键查看列表的方法     \n",
    " \n",
    "2.使用help（查看方法的使用规则）\n",
    "\n",
    "\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9509bb32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"]\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "cbdcab57",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append (\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "86e545b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua', 'Lihua']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1a06fd6f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "e211dace",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "fe283dbe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['lm', 'lm', 'lm', 'lm', 'lm']"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.insert(2,\"lm\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fec57afa",
   "metadata": {},
   "source": [
    " ## 2.列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "e151e7b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "6f4b5ccd",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.remove(\"lm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "7d88ea31",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['lm', 'lm']"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9beff41d",
   "metadata": {},
   "source": [
    "·正确的删除方法的流程         \n",
    "      \n",
    "查询 value是否存在列表当中          \n",
    "对存在的value进行删除        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "c617a651",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Wang\" in names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "40522c39",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[0;32mIn [40]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mnames\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremove\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mWang\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "names.remove(\"Wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "6e98f786",
   "metadata": {},
   "outputs": [],
   "source": [
    "if \"Wang\" in names:\n",
    "    names.remove(\"Wang\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "cd78145f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：删除系统：\n",
    "## 1. 如果输入的值存在，删除；2.如果输入的结果不存在，提示用户查询无结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "279ab903",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua', 'Lihua']"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "54bf444c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入要删除的内容：Lihua\n",
      "删除成功！\n",
      "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']\n"
     ]
    }
   ],
   "source": [
    "user_input_name = input(\"请输入要删除的内容：\")\n",
    "if user_input_name in names:\n",
    "    names.remove(user_input_name)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的结果不存在，删除无效\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d35785c3",
   "metadata": {},
   "source": [
    "·列表的删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "e39de8c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 重新建立names列表数据\n",
    "names = ['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "5a01e2ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "7e81c9c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "4b66e327",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "915513ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Lihua'"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop() # 直接使用pop()，删除最后一位 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "04daad19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "30fc0301",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "b8831ddf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Jan']"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "a02a6124",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "9c12c7ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入删除的索引值：2\n"
     ]
    }
   ],
   "source": [
    "pop_index = int(input(\"输入删除的索引值：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "cf77f31b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "删除成功！\n"
     ]
    }
   ],
   "source": [
    "if pop_index<len(names):\n",
    "    names.pop(pop_index)\n",
    "    print(\"删除成功！\")\n",
    "else:\n",
    "    print(\"您输入的值不在index的范围内\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "1017db64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex']"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f16b4fb7",
   "metadata": {},
   "source": [
    " ## 3. 列表的修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "259dbc31",
   "metadata": {},
   "outputs": [],
   "source": [
    "names[0] = \"lm\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "27fc626c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['lm', 'Alex']"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb3ed13c",
   "metadata": {},
   "source": [
    " ## 4. 列表的其他方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "2bf066a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = ['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "f9cf3209",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "83810c44",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "9fc984c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1 = ['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "93779f1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "bbd62cf5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "d1024de0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓峰', '王丽', '刘明']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class2 = [\"李晓峰\",\"王丽\",\"刘明\"]\n",
    "names_class2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "78fdecc0",
   "metadata": {},
   "outputs": [],
   "source": [
    "names_class1.extend(names_class2) # 注意：使用列表的方法的列表进行扩展"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "7f7758a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua', '李晓峰', '王丽', '刘明']"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names_class1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f2693bc",
   "metadata": {},
   "source": [
    "·sort() 排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "aa92e0b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生 = [230,250,245,255,260,270]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "8d0b11a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(立定跳远_男生.sort)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "70abd4f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "636087a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[230, 245, 250, 255, 260, 270]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "2bd0d5e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远_男生.sort(reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "de12da0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[270, 260, 255, 250, 245, 230]"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "立定跳远_男生"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "561cb7aa",
   "metadata": {},
   "source": [
    " #  while循环\n",
    " \n",
    " · while Ture 是循环概念中非常重要的一种方式。它可以实现for循环的指定次数，也可以在特定条件下停止。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "866707cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是风儿我是沙，缠缠绵绵到天涯.... 0\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 1\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 2\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 3\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 4\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 5\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 6\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 7\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 8\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 9\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 10\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 11\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 12\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 13\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 14\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 15\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 16\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 17\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 18\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 19\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 20\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 21\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 22\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 23\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 24\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 25\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 26\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 27\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 28\n",
      "你是风儿我是沙，缠缠绵绵到天涯.... 29\n"
     ]
    }
   ],
   "source": [
    "#它可以实现for循环的指定次数\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯....\",count)\n",
    "    count = count + 1\n",
    "    if count ==30:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "5bf0296b",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'getpass' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[0;32mIn [90]\u001b[0m, in \u001b[0;36m<cell line: 6>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m## 小游戏：猜数字\u001b[39;00m\n\u001b[1;32m      2\u001b[0m \u001b[38;5;66;03m# 1. hide_card : 0-100 大了， 小了\u001b[39;00m\n\u001b[1;32m      3\u001b[0m \u001b[38;5;66;03m# 2. guess_digit : 50\u001b[39;00m\n\u001b[1;32m      5\u001b[0m count \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m----> 6\u001b[0m hide_card \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[43mgetpass\u001b[49m\u001b[38;5;241m.\u001b[39mgetpass(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhide_card:\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[1;32m      8\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m      9\u001b[0m     guess_digit \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m猜一猜（0-100）：\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n",
      "\u001b[0;31mNameError\u001b[0m: name 'getpass' is not defined"
     ]
    }
   ],
   "source": [
    "## 小游戏：猜数字\n",
    "# 1. hide_card : 0-100 大了， 小了\n",
    "# 2. guess_digit : 50\n",
    "\n",
    "count = 0\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "\n",
    "while True:\n",
    "    guess_digit = int(input(\"猜一猜（0-100）：\"))\n",
    "\n",
    "#对比：\n",
    "if hide_card == guess_digit:\n",
    "    print(\"你超棒！！！\")\n",
    "    break\n",
    "elif guess_digit>hide_card:\n",
    "    print(\"往小猜！加油！\")\n",
    "else:\n",
    "    print(\"往大的猜！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14676622",
   "metadata": {},
   "source": [
    " # 课后练习：\n",
    "\n",
    "1.列表的切片和方法的使用        \n",
    " 1.课本p67         \n",
    " 2.课本p81             \n",
    "2.p89 列表，我们已经知道是什么（列表总结）         \n",
    "课本67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6845fc46",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4170feb7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "     print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ba2cae01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:Find\n",
      "i\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "     print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3088193e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:sky\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "     print(vowel)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f00b5a5",
   "metadata": {},
   "source": [
    "课本P81"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9320592c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()     # 每次for循坏迭代，plist会收缩一个对象，直到后4个对象消失\n",
    "plist.pop(0)  #删除列表开头的“D”\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c5686509",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "new_phrase = ''.join(plist[1:3])  # 从“plist”取出单词“on”\n",
    "new_phrase = new_phrase +''.join([plist[5],plist[4],plist[7],plist[6]]) # 跳出需要的其他字母\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b87d4ecd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
